﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Drawing.Imaging;
using CustomsSystem.Model;
using CustomsSystem.BLL;
using Maticsoft.Common;

namespace WEB
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

           

            if (tbID.Text == "")
            { Response.Write("<script>alert('请输入用户名')</script>"); return; }
            else if (tbPW.Text == "")
            { Response.Write("<script>alert('请输入密码')</script>"); return; }
            else if (tbCode.Text == "")
            {
                Response.Write("<script>alert('请输入验证码')</script>");
                return;
            }
            else
            {
                if (tbCode.Text != Session["checknum"].ToString())
                {
                    Response.Write("<script>alert('验证码错误，请重新输入')</script>");
                    tbCode.Text = "";
                    return;
                }
                else
                {


                    if (RadioButtonList1.SelectedValue == "1")
                    {
                        #region
                        string UserName = tbID.Text.Trim();
                        string PassWord =stringpro .md5 (tbPW.Text.Trim());

                        //验证用户信息
                        CustomsSystem.Model.Users ma = new CustomsSystem.BLL.UserManage().GetModel(UserName, PassWord);

                        if (ma != null)
                        {
                            Session["ID"] = ma.Id;
                            Session["UserName"] = ma.UserName;
                            Session["JobNo"] = ma.JobNo;
                            Session["EmpNo"] = ma.EmpNum;

                            //获取该用户权限信息
                            string EMPNUM = ma.EmpNum;
                            CustomsSystem.Model.Auth au = new CustomsSystem.BLL.AuthManage().GetModel(EMPNUM);
                            if (au != null)
                            {
                                
                                #region  各种权限
                                //第一块
                                Session["工作计划"] = au.工作计划;
                                Session["工作计划录入"] = au.工作计划录入;
                                Session["当天业务查看"] = au.当天业务查看;
                                Session["将来业务查看"] = au.将来业务查看;
                                Session["查看业务计划"] = au.查看业务计划;
                              //第二块
                                Session["业务管理"] = au.业务管理;
                                Session["查看任务列表"] = au.查看任务列表;
                                Session["委托单录入"] = au.委托单录入;
                                Session["委托单查看"] = au.委托单查看;
                                Session["报关单证上载"] = au.报关单证上载;
                                Session["上载单证查看"] = au.上载单证查看;
                                //第三块
                                Session["客户管理"] = au.客户管理;
                                Session["查看客户信息"] = au.查看客户信息;
                                Session["增加客户信息"] = au.增加客户信息;
                                Session["合同管理"] = au.合同管理;
                                //第四块
                                Session["费用结算"] = au.费用结算;
                                Session["费用录入"] = au.费用录入;
                                Session["审核费用"] = au.审核费用;
                                Session["反审核"] = au.反审核 ;
                                Session["费用销账"] = au.费用销账;
                                Session["对账单"] = au.对账单;
                                Session["结算单"] = au.结算单;
                                //第五块
                                Session["统计分析"] = au.统计分析;
                                Session["应实收统计"] = au.应实收统计;
                                Session["单证交接签收表"] = au.单证交接签收表;
                                Session["员工业务统计"] = au.员工业务统计;
                                Session["业务数据统计"] = au.业务数据统计;
                                //第六块
                                Session["客户互动"] = au.客户互动;
                                Session["客户意见反馈栏"] = au.客户意见反馈栏;
                                Session["短信发送"] = au.短信发送;
                                //第七块
                                Session["知识分享"] = au.知识分享;
                                Session["行业法律法规"] = au.行业法律法规;
                                Session["业务流程"] = au.业务流程;
                                Session["典型案例"] = au.典型案例;
                                Session["管理公告"] = au.管理公告;
                                Session["资源上传"] = au.资源上传;
                                Session["港口情况"] = au.港口情况;
                                //第八块
                                Session["基础资料设置"] = au.基础资料设置;
                                Session["EXCEL模板设置"] = au.EXCEL模板设置;
                                Session["费用类别设置"] = au.费用类别设置;
                                Session["费用模板设置"] = au.费用模板设置;
                                Session["单证模板设置"] = au.单证模板设置;
                                Session["基础代码设置"] = au.基础代码设置;
                                Session["岗位设置"] = au.岗位设置;
                                Session["代码查询"] = au.代码查询;
                                Session["查看人员"] = au.查看人员;
                                Session["增加人员"] = au.增加人员;
                                Session["密码修改"] = au.密码修改;
                                //第九块

                                Session["系统管理"] = au.系统管理;                              
                                Session["权限管理"] = au.权限管理;
                                Session["数据管理"] = au.数据管理;
                                #endregion
                                Response.Redirect("index.aspx");
                            }
                            else MessageBox.ShowAndRedirect(this, "您没有任何权限，请管理员为您添加权限后再登陆", "login.aspx");
                        }
                        else
                        {
                            Response.Write("<script>alert('用户名或密码错误，请重新输入！')</script>");

                        }
                        #endregion
                    }

                    else
                    { //指定客户
                        string ClientName = tbID.Text.Trim();
                        string PassWord = stringpro .md5 (tbPW.Text.Trim());
                        CustomsSystem.Model.Client ma = new CustomsSystem.BLL.ClientManage().GetModel(ClientName, PassWord);
                        if (ma != null)
                        {
                           
                            Session["ID"] = ma.ID;
                            Session["ClientName"] = ma.ClientName;
                            Response.Redirect("client_index.aspx");
                        }
                        else
                        {
                            Response.Write("<script>alert('用户名或密码错误，请重新输入！')</script>");
                        }
                    }
                }

            }
        }
    }
}
